import java.util.PriorityQueue;

/**
 * @author LKQ
 * @date 2022/2/23 14:40
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.sortEvenOdd(new int[]{4, 1, 2, 3});
    }
    public int[] sortEvenOdd(int[] nums) {
        int n = nums.length;
        // 小顶堆，非递增
        PriorityQueue<Integer> ou = new PriorityQueue<>();
        // 大顶堆，非递减
        PriorityQueue<Integer> ji = new PriorityQueue<>((a, b) -> b - a);
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                ou.offer(nums[i]);
            }else {
                ji.offer(nums[i]);
            }
        }
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                nums[i] = ou.poll();
            }else {
                nums[i] = ji.poll();
            }
        }
        return nums;
    }
}
